package com.situ.mydictionary;

import android.content.ContentValues;
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.situ.mydatabase.MyDatabaseHelper;

public class AddActivity extends AppCompatActivity {

    private Button back, submit;
    private EditText input;
    private MyDatabaseHelper mydb;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_layout);

        mydb = new MyDatabaseHelper(this, "Mysentence.db", null, 1);

        back = (Button)findViewById(R.id.back);
        submit = (Button)findViewById(R.id.submit);
        input = (EditText)findViewById(R.id.input);

        submit.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
//                Add();
                SQLiteDatabase sqldb = mydb.getWritableDatabase();
                ContentValues values = new ContentValues();

                values.put("contain", input.getText().toString());
                if (input.getText().toString() !=null && !input.getText().toString().equals("")){
                    sqldb.insert("Words", null, values);
                    values.clear();
                    Toast.makeText(AddActivity.this,input.getText().toString()+"input success", Toast.LENGTH_SHORT).show();
                }

                //Toast.makeText(AddActivity.this,"add sucesss", Toast.LENGTH_SHORT).show();

            }
        });
        back.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v){
                finish();
            }
        });
    }
}
